# _*_ coding : utf-8 _*_
# @Time : 2023/8/26 23:04
# @Author : 寻梦
# @File : 16_解析_站长素材图片
# @Project : code
import urllib.request
from lxml import etree
# 站长素材官网：https://sc.chinaz.com/
# 解析地址：https://sc.chinaz.com/tupian/siwameinvtupian.html

url="https://sc.chinaz.com/tupian/siwameinvtupian.html"
request=urllib.request.Request(url=url)
response=urllib.request.urlopen(request)
content=response.read().decode('utf8')
tree=etree.HTML(content)
image_list=tree.xpath('//div[contains(@class,"com-img-txt-list")]/div/img/@data-original')
name_list=tree.xpath('//div[contains(@class,"com-img-txt-list")]/div/img/@alt')
for num in range(len(image_list)):
    image_url="https:"+image_list[num]
    urllib.request.urlretrieve(image_url,'data/images/'+name_list[num]+".jpg")